<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('流程审批')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: jasny-bootstrap-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
	<style>
		.file-preview {
		    padding: 0;
		    margin-bottom: 0;
		    border-radius: 0;
		    border: none;
		}
		
		.krajee-default.file-preview-frame {
		    margin-right: 20px;
		    padding: 0;
		    border: none;
		    box-shadow: none;
		}
		
		.krajee-default.file-preview-frame:not(.file-preview-error):hover {
		    border: none;
		    box-shadow: none;
		}
		
		.krajee-default .file-footer-caption {
			margin-bottom: 0;
		}
		
		.krajee-default.file-preview-frame .file-thumbnail-footer {
		    height: auto;
		}
		
		.krajee-default .file-caption-info {
			width: auto;
		}
		
		.kv-upload-progress .progress {
			margin-top: 0;
		}
		
		.krajee-default.file-preview-frame .kv-file-content,
		.krajee-default .file-size-info,
		.krajee-default .file-upload-indicator,
		.file-input .kv-file-upload,
		.file-input .kv-file-zoom {
			display: none;
		}
		
		.file-input .kv-file-remove {
			position: absolute;
			top: 3px;
			right: -15px;
			height: 14px;
			padding: 0;
			margin: 0;
			border: none;
			background: none;
		}
		
		.file-input .kv-file-remove:active, 
		.file-input .kv-file-remove:focus {
			background: none;
			outline: none;
			box-shadow: none;
		}
		
		.file-input .kv-file-remove .glyphicon-trash {
			color: red;
		}
	</style>
    <style type="text/css">
        table label.error{position: inherit;}select + label.error{z-index:1;right:40px;}
    </style>
</head>
<body class="white-bg">
<div class="col-sm-8">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-sjcontract-add" th:object="${obj}">
    	<h4 class="form-header h4">基本信息</h4>
    		<input type="hidden" id="approvename" name="approvename" th:value="${approvename}" />
            <input name="id" th:field="*{id}" type="hidden">
            <input type="hidden" id="zilwj" name="zilwj" th:value="*{zilwj}" />
            <input name="gcProjectid" type="hidden" th:field="*{gcProjectid}" />
            <div class="form-group">   
            	<label class="col-sm-1 control-label is-required">项目名称：</label>
                <div class="col-sm-2">
                    <input name="gcProjectname" th:field="*{gcProjectname}" class="form-control" type="text" autoComplete="off" required readonly="readonly">
                </div>
                <label class="col-sm-1 control-label is-required">收款单位：</label>
                <div class="col-sm-2">
                	<input name="skdw" th:field="*{skdw}" class="form-control" type="text" autoComplete="off" required readonly="readonly" >
                </div>
                <label class="col-sm-1 control-label is-required">申请人：</label>
                <div class="col-sm-2">
                    <input name="fksqr" th:field="*{fksqr}" class="form-control" type="text" autoComplete="off" required readonly="readonly" >
                </div>
                <label class="col-sm-1 control-label is-required">报销部门：</label>
                <div class="col-sm-2">
                    <input name="dept" class="form-control" type="text" th:field="*{dept}" autoComplete="off" readonly="readonly" required>
                </div>
            </div>
            <div class="form-group">    
            	<label class="col-sm-1 control-label is-required">项目所属：</label>
                <div class="col-sm-2">
                    <select name="authority" th:field="*{authority}" class="form-control" readonly="readonly" required>
						<option th:each="cl:${deptlis}" th:value="${cl.deptId}" th:text="${cl.deptName}"></option>
					</select>
                </div>
                <label class="col-sm-1 control-label is-required">付款单位：</label>
            	<div class="col-sm-2">
            		<select name="ztdw" th:field="*{ztdw}" class="form-control" th:with="type=${@dict.getType('sj_gongs')}" readonly="readonly" required>
                    	<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                	</select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label">资料文件：</label>
                <div class="col-sm-11" style="margin-top: 8px;" id="zlwjlink">
                </div>
            </div>
            <h4 class="form-header h4" style="margin-top: 8px;margin-bottom: 0px;">表单项</h4>
            <div class="row" >
                <div class="col-sm-12">
				    <table id="bootstrap-table"></table>
                </div>
            </div>
        <h4 class="form-header h4" style="margin-top: 18px;">审核信息</h4>
        <div class="form-group">
            <label class="col-sm-2 control-label ">审批结果：</label>
            <div class="col-sm-4">
                <label class="radio-box">
                    <input type="radio" checked="" value="true" name="level3approve">同意</label>
                <label class="radio-box">
                    <input type="radio" value="false" name="level3approve">拒绝</label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">审批意见：</label>
            <div class="col-sm-10">
                <textarea rows="5" name="fwshyj" class="form-control" required></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-3 col-sm-offset-3">
                <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                <input type="hidden"  name="status" id="status" th:value="1">
                <input type="hidden"  name="id" id="id" th:value="${obj.id}">
                <button class="btn btn-primary" onclick="submitHandler()" type="button"><i class="fa fa-check"></i>&nbsp;提交</button>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:src="@{/ruoyi/base64.min.js?v=20231208}"></script>
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <th:block th:include="include :: bootstrap-suggest-js" />
    <th:block th:include="include :: bootstrap-typeahead-js" />
<script th:src="@{/js/jquery.tmpl.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "task/manage"
    $("#form-sjcontract-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
    	if ($.validate.form()) {
        var taskid = $("#taskid").val();
        var check = document.querySelector("input[name='level3approve']:checked").value;
        if(check=="false"){
        	$("#status").val(4);
        }else{
        	$("#status").val(2);
        }
        var comment = $("textarea[name=fwshyj]").val();
        
        $.operate.save("edit4check", $('#form-sjcontract-add').serialize(), function(){
        	var json = {"level3approve": check, "level4": $("#approvename").val(), "comment": comment};
	        $.ajax({
	            url : prefix + "/completeTask/" + taskid,
	            type : "POST",
	            data : JSON.stringify(json), //转JSON字符串
	            dataType: 'json',
	            contentType:'application/json;charset=UTF-8', //contentType很重要
	            success : function(result) {
	                $.modal.msg("办理成功");
	                const parent = window.parent;
	                // 我的待办
	                const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
	                // 我的全部待办
	                const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
	                myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
	                myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
	                $.modal.closeTab();
	            }
	        });
	        
        });
    	}
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
                $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                    "<i class=\"fa fa-briefcase\"></i></div>" +
                    "<div class=\"vertical-timeline-content\">" +
                    "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                    "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                    "<p>" + (data[a].comment || "-") + "</p>" +
                    "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                    "</div>" +
                    "</div>");
            }
        });
    });
    
    $("input[name='bxrAt']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $(function() {
    	var data = [[${obj.gcBszbzfditem}]];
    	// 初始化数据, 可以由后台传过来
	    var options = {
	    	data: data,
            pagination: false,
	        showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sidePagination: "client",
	        columns: [
	        {
	        	field: 'index',
	        	align: 'center',
	        	title: "序号",
                formatter: function (value, row, index) {
                	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                	var columnId = $.common.sprintf("<input type='hidden' name='gcBszbzfditem[%s].xuh' value='%s'>", index, row.id);
                	return columnIndex + $.table.serialNumber(index) + columnId;
                }
            },
	        {
	            field: 'descs',
	            align: 'center',
	            title: '支付事项摘要说明',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input class='form-control itemdescs' type='hidden' autoComplete='off' name='gcBszbzfditem[%s].descs' value='%s'>", index, value);
	        		return html+value;
                }
	        },
//		        {
//		            field: 'type',
//		            align: 'center',
//		            title: '支付方式',
//		            width:180,
//		            formatter: function(value, row, index) {
//		        		var data = [{ index: index, type: value }];
//		                return $("#itemType").tmpl(data).html();
//                 }
//		        },
	        {
	            field: 'jine',
	            align: 'center',
	            title: '支付金额',
	            width:180,
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input class='form-control itemjine' type='hidden' autoComplete='off' name='gcBszbzfditem[%s].jine' value='%s'>", index, value);
	        		return html+value;
                }
	        },
	        {
	            field: 'memo',
	            align: 'center',
	            title: '备注',
	            width:360,
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input class='form-control' type='hidden' autoComplete='off' name='gcBszbzfditem[%s].memo' value='%s'>", index, value);
	        		return html+value;
                }
	        }]
	    };
	    $.table.init(options);
	    
	    
		var zilwj = $("#zilwj").val();
    	
    	var n=zilwj.split(",");
    	for(var i=0;i<n.length;i++){
//     		var url = "http://lkgnews.cn:8012/onlinePreview?url="+encodeURIComponent(Base64.encode(n[i]));
    		var url = n[i];
    		$("#zlwjlink").append("<a href='"+url+"' target='_blank' >"+n[i]+"</a><br>");
    	}
    	
    	// 多图上传
       $("#multipleFile").fileinput({
           uploadUrl: "/gcgl/bszbzfd/uploads",
           uploadAsync: false,
           showClose: false,
           showCancel: false,
           dropZoneEnabled: false,
           buttonLabelClass: ''
       }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
       	var rsp = data.response;
           log.info("reutrn fileNames：" + rsp.fileNames)
		   $("#zilwj").val(rsp.fileNames);
       }).on('fileremoved', function (event, id, index) {
           $("input[name='" + event.currentTarget.id + "']").val('')
       })
	});
    
    $.validator.addMethod("itemtype", function(value, element) {
        return !this.optional(element);
    }, "支付方式必填。");
    $.validator.addMethod("itemdescs", function(value, element) {
        return !this.optional(element);
    }, "支付事项摘要说明必填。");
    $.validator.addMethod("itemjine", function(value, element) {
        return !this.optional(element) && (value <= 10000000 && value >= 1);
    }, "支付金额长度区间1-10000000。");
    
</script>
</body>
</html>

<!-- 成本类型 -->
<script id="itemType" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='gcBszbzfditem[${index}].type'>
    <option value="电汇" {{if type==="电汇"}}selected{{/if}}>电汇</option>
<option value="现金" {{if type==="现金"}}selected{{/if}}>现金</option>
<option value="承兑" {{if type==="承兑"}}selected{{/if}}>承兑</option>
<option value="转账" {{if type==="转账"}}selected{{/if}}>转账</option>
<option value="其他" {{if type==="其他"}}selected{{/if}}>其他</option>
</select>
</div>
</script>